package spass;

import javax.swing.JFrame;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import spass.raytracer.RayTracer;
import spass.renderer.PixelCanvas;
import spass.scene.Scene;

public class Main {
    public static void main(String[] args) {
        PixelCanvas renderer = createPixelCanvas();

        ApplicationContext context = new ClassPathXmlApplicationContext("META-INF/beans.xml");

        RayTracer rayTracer = context.getBean(RayTracer.class);
        Scene scene = context.getBean(Scene.class);

        rayTracer.render(scene, renderer);
    }

    private static PixelCanvas createPixelCanvas() {
        PixelCanvas pixelCanvas = new PixelCanvas(1000, 1000);

        JFrame frame = new JFrame("Raytracer Demo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.add(pixelCanvas);
        frame.pack();
        frame.setVisible(true);

        return pixelCanvas;
    }
}
